﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SilverlightTest
{
    public partial class Home : Page
    {
        System.Windows.Threading.DispatcherTimer secondsTimer = new System.Windows.Threading.DispatcherTimer();
        bool flag = false;
        int i = 1;
        int j = 1;
        int moveDown = 0;
        int moveHorizontal = 200;


        Rectangle block = new Rectangle()
        {

            Height = 25,
            Width = 25,
            Fill = new SolidColorBrush { Color = Color.FromArgb(80, 143, 12, 28) },
            Stroke = new SolidColorBrush(Colors.Black)
        };

        public Home()
        {
            InitializeComponent();
            
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        //Start Button
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (flag == false)
            {
                secondsTimer.Interval = new TimeSpan(0, 0, 0, 1, 0);
                secondsTimer.Tick += new EventHandler(Each_Sec_Tick);
                secondsTimer.Tick += new EventHandler(Move_Shape);
                secondsTimer.Start();
                flag = true;
            }
            else
            {
                secondsTimer.Start();
            }

            gameArea.Children.Add(block);
            Canvas.SetLeft(block, 200);
            Canvas.SetTop(block, 0);
        }

        public void Each_Sec_Tick(object o, EventArgs sender)
        {
            if (i < 10)
            {
                timeSec.Text = "0" + i.ToString();
                i++;
                
            }
            else
            {
                timeSec.Text = i.ToString();
                i++;
            }

            if (i == 61)
            {
                timeSec.Text = "00";
                i = 1;
                if (j < 10)
                {
                    timeMin.Text = "0" + j.ToString() + ":";
                    j++;
                }
                else
                {
                    timeMin.Text = j.ToString() + ":";
                    j++;
                }
            }

        }

        public void Move_Shape(object o, EventArgs sender)
        {
            if (moveDown <= 400)
            {
                moveDown += 25;

                Canvas.SetTop(block, 0 + moveDown);
            }
        }

        //Pause Button
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            secondsTimer.Stop();
        }


        private void UserControl_KeyUp(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
                case Key.Left:
                    moveHorizontal -= 25;
                    Canvas.SetLeft(block, moveHorizontal);
                    break;
                case Key.Right:
                    moveHorizontal += 25;
                    Canvas.SetLeft(block, moveHorizontal);
                    break;

            }
        }
  
    
    }
}